package com.yb.guigu.pick.rabbitmq.messager.config;

import com.yb.guigu.pick.core.constant.RabbitMQConstant;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Copyright (C), 2022-2023, 姚兵
 * Author: 32210
 * Date: 2023/6/13 13:23
 * FileName: DeadLetterConfig
 * Description:
 */

@Configuration
public class DeadLetterConfig {

    @Bean
    public Exchange deadLetterExchange(){
        return ExchangeBuilder.directExchange(RabbitMQConstant.DeadLetterQueueConstant.EXCHANGE).durable(true).build();
    }

    @Bean
    public Queue deadLetterQueue(){
        return QueueBuilder.durable(RabbitMQConstant.DeadLetterQueueConstant.QUEUE).build();
    }


    @Bean
    public Binding  deadLetterBinding(Queue deadLetterQueue,Exchange deadLetterExchange){
        return BindingBuilder.bind(deadLetterQueue).to(deadLetterExchange).with(RabbitMQConstant.DeadLetterQueueConstant.ROUTING_KEY).noargs();
    }
}
